package cn.virens.service.impl.platform.generator.common;

import java.io.Serializable;

import cn.hutool.core.util.StrUtil;

public class TableInfo implements Serializable {
	private static final long serialVersionUID = 1465609596528255056L;

	private String date;// 创建时间 eg:2018-08-01
	private String name; // 表名（中文） eg:用户表

	private String modelName;
	private String modelPath;
	private String modelTable; // 表名 eg:sys_user
	private String modelPackage;

	private String controlName;
	private String controlPath;
	private String controlMapping;
	private String controlPackage;
	private String controlIdentity;

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getModelName() {
		return modelName;
	}

	public String getModelPath() {
		return modelPath;
	}

	public String getModelTable() {
		return modelTable;
	}

	public void setModelTable(String modelTable) {
		this.modelName = StrUtil.upperFirst(StrUtil.toCamelCase(modelTable));
		this.modelTable = StrUtil.trim(modelTable);
	}

	public String getModelPackage() {
		return modelPackage;
	}

	public void setModelPackage(String modelPackage) {
		this.modelPath = StrUtil.replace(modelPackage, ".", "/");
		this.modelPackage = StrUtil.trim(modelPackage);
	}

	public String getControlName() {
		return controlName;
	}

	public void setControlName(String controlName) {
		this.controlIdentity = StrUtil.toSymbolCase(controlName, ':');
		this.controlName = StrUtil.trim(controlName);
	}

	public String getControlPath() {
		return controlPath;
	}

	public String getControlPackage() {
		return controlPackage;
	}

	public String getControlMapping() {
		return controlMapping;
	}

	public void setControlMapping(String controlMapping) {
		this.controlPath = StrUtil.subBefore(controlMapping, '/', true);
		this.controlPackage = StrUtil.replace(controlPath, "/", ".");
		this.controlMapping = StrUtil.trim(controlMapping);
	}

	public String getControlIdentity() {
		return controlIdentity;
	}

	public String getControlPathByTpl() {
		int pathSize = StrUtil.count(controlMapping, '/');
		StringBuilder builder = new StringBuilder("../");
		for (int i = 0; i < pathSize; i++) {
			builder.append("../");
		}

		return builder.toString();
	}
}
